#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=1e5+5;
int n,m,A[N],X[N],c[N],T,K,a[N];
char d[N][N];

void getK(){
    while((1<<K) < n){
        ++K;
    }
}

int main(){
    int varX0,varX1,varX2,varX3;
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	iostream::sync_with_stdio(false);
	cin.tie(0);

    cin>>n>>m;
    for(int i=0;i<n;++i){
        cin>>A[i];
    }
    for(int i=0;i<m;++i){
        cin>>c[i];
    }
    getK();
    // cout<<K;
    for(int i=0;i<K;++i){
        cin>>d[i];
    }
    cin>>T;
    while(T--){
        cin>>varX0>>varX1>>varX2>>varX3;
        for(int i=0;i<n;++i){
            switch(i%4){
                case 0:
                    a[i]=A[i]^varX0;
                break;
                case 1:
                    a[i]=A[i]^varX1;
                break;
                case 2:
                    a[i]=A[i]^varX2;
                break;
                case 3:
                    a[i]=A[i]^varX3;
                break;
                default:
                break;
            }
        }
    }

	return 0;
}